package com.tiger.cmpeb.sample2;

import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class Client {
    public static void main(String args[]) {
        try {
            InitialContext ctx = new InitialContext();
            Object obj = ctx.lookup("comp/env/ejb/CustomerBean02");
            CustomerHome02 customerHome =
                (CustomerHome02)PortableRemoteObject.narrow(
                obj, CustomerHome02.class);
            
            Address01 address = new Address01("100-0001", "Tokyo", "Suginami", "ABC 1-1-1");
            Customer02 customer1 = customerHome.create(new Integer(0), "Suzuki Taro", address);
            
            address = new Address01("100-0002", "Tokyo", "Setagaya", "ZZZ 1-2-3");
            Customer02 customer2 = customerHome.create(new Integer(1), "Sasaki Taro", address);
            
            for(int i = 0; i < 2; i++) {
                Customer02 customer = customerHome.findByPrimaryKey(new Integer(i));
                System.out.println(
                    "CustomerID = " + customer.getCustomerID() +
                    " Name = " + customer.getName() +
                    " Address = " + customer.getAddress()
                );
            }
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}
